package com.sinoglobal.sinostore.activity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ListView;

import com.alibaba.fastjson.JSON;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.lidroid.xutils.util.LogUtils;
import com.sinoglobal.sinostore.R;
import com.sinoglobal.sinostore.StateBaseActivity;
import com.sinoglobal.sinostore.adapter.ZiquAddressAdapter;
import com.sinoglobal.sinostore.bean.AddressListVo;
import com.sinoglobal.sinostore.system.Constants;
/**
 * 
* @title: ZiquAddressActivity.java 
* @package com.chiliring.sinostore.activity 
* @description: TODO(自取地址列表) 
* @author LK
* @date 2015-1-16 下午1:48:31
 */
public class ZiquAddressActivity extends StateBaseActivity {
	
	/**自取地址列表**/
//	@ViewInject(R.id.lv_ziqu_address_list)
	private ListView lvZiquAddressList;
	
	private ZiquAddressAdapter ziquAddressAdapter;
	
	/**产品Id**/
	private String pId;
	/**商家Id**/
	private String shopId;
	/**商品id**/
	private String goodsId;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.shop_activity_ziqu_address);
		titleView.setText("自取地址");
		openChenJInShi();
//		ViewUtils.inject(this);
		lvZiquAddressList=getViewById(R.id.lv_ziqu_address_list);
		initData();
	}
	
	
	private void initData(){
		pId = getIntent().getStringExtra("pId");
		shopId = getIntent().getStringExtra("shopId");
		goodsId = getIntent().getStringExtra("goodsId");
		final ProgressDialog progressDialog = new ProgressDialog(ZiquAddressActivity.this);
		try {
			progressDialog.show();
		} catch (Exception e) {
		}
		HttpUtils httpUtils = new HttpUtils();
		RequestParams params = new RequestParams();
		params.addQueryStringParameter("por","500");//请求接口
		params.addQueryStringParameter("p_id",pId); //产品ID
		params.addQueryStringParameter("shop_id",shopId);//商家ID
		params.addQueryStringParameter("goods_id",goodsId);//商品ID
		params.addQueryStringParameter("proIden",Constants.STOREFLAG);
		httpUtils.send(HttpMethod.POST, Constants.STORE_URL, params, new RequestCallBack<String>() {
			@Override
			public void onStart() {
				super.onStart();
				LogUtils.i("url="+this.getRequestUrl());
			}
			@Override
			public void onFailure(HttpException arg0, String arg1) {
				try {
					progressDialog.dismiss();
				} catch (Exception e) {
				}
			}

			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				try {
					progressDialog.dismiss();
				} catch (Exception e) {
				}
				String result = responseInfo.result;
				if(!TextUtils.isEmpty(result)){
					AddressListVo entity = JSON.parseObject(result, AddressListVo.class);
					if(Constants.STORE_SUCCESS_CODE.equals(entity.getCode())){
						ziquAddressAdapter = new ZiquAddressAdapter(ZiquAddressActivity.this, entity.getList());
						lvZiquAddressList.setAdapter(ziquAddressAdapter);
					}
				}
			}
		});
	}
}
